import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'

Vue.use(Vuex);

const vuexLocal = new VuexPersistence({
  storage: window.sessionStorage
})

const store = new Vuex.Store({
  state: {
    token: undefined,
    userId: undefined,
    userName: undefined,
    role: undefined,
    info: undefined
  },
  mutations: {
    SetToken(state, token) {
      state.token = token
    },
    SetUserId(state, userId) {
      state.userId = userId
    },
    SetUserName(state, userName) {
      state.userName = userName
    },
    SetRole(state, role) {
      state.role = role
    },
    SetInfo(state, info) {
      state.info = info
    },
    Logout(state) {
      state.token = undefined
      state.userName = undefined
      state.userId = undefined
      state.role = undefined
      state.info = undefined
    }
  },
  plugins: [vuexLocal.plugin]

});

export default store
